package com.orange.score.network;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class ImageNetworkRequest extends AsyncTask<ImageView, Void, Bitmap>
{
  public static final String TAG = ImageNetworkRequest.class.getName();
  ImageView imageView = null;

  private Bitmap downloadImage(String paramString)
  {
    Bitmap localBitmap1;
    URLConnection localURLConnection;
    try
    {
      localURLConnection = new URL(paramString).openConnection();
      localURLConnection.connect();
      InputStream localInputStream = localURLConnection.getInputStream();
      BufferedInputStream localBufferedInputStream = new BufferedInputStream(localInputStream);
      Bitmap localBitmap2 = BitmapFactory.decodeStream(localBufferedInputStream);
      localBufferedInputStream.close();
      localInputStream.close();
      localBitmap1 = localBitmap2;
      return localBitmap1;
    }
    catch (IOException localIOException)
    {
      Log.w(TAG, "Error getting the image from server : " + localIOException.getMessage().toString());
      localBitmap1 = null;
    }
  }

  protected Bitmap doInBackground(ImageView[] paramArrayOfImageView)
  {
    this.imageView = paramArrayOfImageView[0];
    return downloadImage((String)this.imageView.getTag());
  }

  protected void onPostExecute(Bitmap paramBitmap)
  {
    if (paramBitmap != null)
      this.imageView.setImageBitmap(paramBitmap);
  }
}